package org.skywork.top.flow.service.impl;

import org.flowable.task.api.Task;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.skywork.top.flow.service.IFlowableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FlowableServiceImpl implements IFlowableService {

    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private TaskService taskService;

    // 启动流程
    public void startProcess() {
        runtimeService.startProcessInstanceByKey("approval");
    }

    // 查询待办任务
    public List<Task> getTasks(String assignee) {
        return taskService.createTaskQuery()
                .taskAssignee(assignee)
                .list();
    }

    // 完成任务
    public void completeTask(String taskId) {
        taskService.complete(taskId);
    }
}
